package com.ruoyi.system.service.waterService.waterServiceImpl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.waterEnity.UserEntity;
import com.ruoyi.system.domain.waterEnity.UserInfoBO;
import com.ruoyi.system.mapper.waterMapper.UserMapper;
import com.ruoyi.system.service.waterService.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserEntity selectUserById(int id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public List<UserInfoBO> getAllUser() {
        return userMapper.getAllUser();
    }

    @Override
    public int updateIdentify(UserEntity userEntity) {
        return userMapper.updateIdentify(userEntity);
    }

    @Override
    public int deleteUser(String ids) {
        Long[] userIds = Convert.toLongArray(ids);
        int num = userMapper.deleteUser(userIds);
        if (num>0){
            return 1;
        }else{
            return 0;
        }
    }

    @Override
    public List<UserInfoBO> selectUserByListId(String ids) {
        Long[] userids = Convert.toLongArray(ids);
        List<UserInfoBO> userEntityList = userMapper.selectStoreByListId(userids);
        return userEntityList;
    }

    @Override
    public List<UserInfoBO> selectUserList(String username, String building, String identify) {
        String flag = username + building +identify;
        List<UserInfoBO> list =null;
        if (StringUtils.isEmpty(flag)){
            list = userMapper.getAllUser();
        }else if (StringUtils.isNotEmpty(username)){
            list = userMapper.selectUserByUsername(username);
        }else if (StringUtils.isNotEmpty(building)){
            list = userMapper.selectUserByBuilding(building);
        }else  if (StringUtils.isNotEmpty(identify)){
            list = userMapper.selectUserByIdentify(identify);
        }else {
            list = userMapper.getAllUser();
        }
        return list;
    }
}
